﻿import QtQuick 2.12
import QtQuick.Window 2.12
import Moudle.widget 1.0
import Qt.labs.calendar 1.0
Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Rectangle
    {
        anchors.fill: parent
        color: "red"
        Text {
            id: name
            width: 216
            height: 48
            text: qsTr("text")
            anchors.centerIn: parent
            font.pixelSize: 14

        }
        MouseArea
        {
            anchors.fill: parent
            anchors.rightMargin: 1
            anchors.bottomMargin: 3
            anchors.leftMargin: -1
            anchors.topMargin: -3
            // 鼠标点击 触发 widget 的信号
            onClicked:
            {
                // 调用 function 带有参数
                hwidget.function(123)
                // 调用 function1 带有参数 以及返回值， 返回给 text 并显示
                name.text = hwidget.function1("黑塞")
            }

            GridView {
                id: gridView
                x: 44
                y: 52
                width: 140
                height: 140
                cellWidth: 70
                model: ListModel {
                    ListElement {
                        name: "Grey"
                        colorCode: "grey"
                    }

                    ListElement {
                        name: "Red"
                        colorCode: "red"
                    }

                    ListElement {
                        name: "Blue"
                        colorCode: "blue"
                    }

                    ListElement {
                        name: "Green"
                        colorCode: "green"
                    }
                }
                delegate: Item {
                    x: 5
                    height: 50
                    Column {
                        Rectangle {
                            width: 40
                            height: 40
                            color: colorCode
                            anchors.horizontalCenter: parent.horizontalCenter
                        }

                        Text {
                            x: 5
                            text: name
                            anchors.horizontalCenter: parent.horizontalCenter
                            font.bold: true
                        }
                        spacing: 5
                    }
                }
                cellHeight: 70
            }
        }
    }
    Widget
    {
        id: hwidget  // id 也可以认为是 widget 类型的别名
    }
}
